package ar.com.poo.vista;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JLabel;

import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

import ar.com.poo.controlador.GestionTelefonia;
import ar.com.poo.modelo.Servicio;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class ConsultaDeServicio extends javax.swing.JFrame {

	private static ConsultaDeServicio app;
	private JTable jTableServicio;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ConsultaDeServicio inst = new ConsultaDeServicio();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);

			}
		});
	}

	public static ConsultaDeServicio getInstancia() {
		if (app == null)
			app = new ConsultaDeServicio();
		return app;
	}

	public ConsultaDeServicio() {
		super();
		initGUI();
	}

	private void initGUI() {
		
		try {
			{
				getContentPane().setLayout(null);
				getContentPane().add(getJTableServicio());

				
			}
			{
				this.setSize(546, 186);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private JTable getJTableServicio() {
		if(jTableServicio == null) {
			
						
			DefaultTableModel  modelo = new DefaultTableModel();
			
			modelo.addColumn("Name");
			modelo.addColumn("Years");
		
			jTableServicio = new JTable(modelo);
			getFilas(modelo);

			jTableServicio.setBounds(139, 37, 283, 110);
		}
		return jTableServicio;
	}

	
	
	private void getFilas(DefaultTableModel  modelo){
		
		GestionTelefonia sist = GestionTelefonia.getInstancia();		
		
		Collection<Servicio> servicios = sist.listarServicios();
		
		ArrayList<ArrayList> dataTable = new ArrayList<ArrayList>();
		
		for (Iterator iterator = servicios.iterator(); iterator.hasNext();) {
			Servicio servicio = (Servicio) iterator.next();
			
			ArrayList row =  new ArrayList();
			row.add(servicio.getNombre());
			row.add(servicio.getValorUnitario());

			dataTable.add(row);
		}
		
		
		
		Collection<ArrayList> filas = dataTable;
		
		int i = 0;
		for (Iterator iterator = filas.iterator(); iterator.hasNext();) {
			ArrayList fila = (ArrayList) iterator.next();
			modelo.insertRow(i, fila.toArray());
			i++;
		}
		
		
	}
	
}
